package cn.com.klun.tjy.logic.impl;

import cn.com.klun.inter.ILogics;
import cn.com.klun.tjy.common.constant.ResultEnum;
import cn.com.klun.tjy.common.util.DateUtils;
import cn.com.klun.tjy.common.util.TaskConstants;
import cn.com.klun.tjy.dao.entity.TblStockDaykInfo;
import cn.com.klun.tjy.dao.mapper.edit.TblStockDaykInfoEditMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;


/** 
 * @ClassName: DayKUpdateLockLogic
 * @Description: 更新日K定时任务定时器锁表
 * @author wangheming
 * @date 2018年1月16日 13:46
 */
@Service
public class DayKUpdateLockLogic implements ILogics<Map<String, Object>> {
	
	private Logger logger = LoggerFactory.getLogger("DayKUpdateLockLogic");

	@Autowired
	private TblStockDaykInfoEditMapper tblStockDaykInfoEditMapper;

	@Override
	public ResultEnum exec(Map<String, Object> map) throws Exception {
		logger.info("更新日K定时任务加锁开始,日志关联KEY：{}",map.get("_LOG_AND_KEY"));
		try{
			TblStockDaykInfo tblStockDaykInfo = (TblStockDaykInfo) map.get("tblStockDaykInfo");
			logger.info("更新日K定时任务定时器锁定开始,日志关联KEY：{}",map.get("_LOG_AND_KEY"));
			Map<String, Object> lockMap = new HashMap<String, Object>();
			lockMap.put("kId", tblStockDaykInfo.getKId());
			lockMap.put("lockFlag", TaskConstants.LOCK_FLG_NO);
			lockMap.put("lockFlagNew", TaskConstants.LOCK_FLG_ING);
			lockMap.put("updateTimeNew", DateUtils.getCurrDateTime());
			int count = tblStockDaykInfoEditMapper.editInfo(lockMap);
			if(count == 1){
				logger.info("更新日K定时任务加锁成功,日志关联KEY：{}",map.get("_LOG_AND_KEY"));
				return ResultEnum.OK;
			}
		}catch(Exception e){
			logger.error("更新日K定时任务加锁异常,日志关联KEY：{}" , map.get("_LOG_AND_KEY"),e);
			return ResultEnum.PART_CASE_01;
		}
		return ResultEnum.PART_CASE_01;
	}

}
